package com.lebang.medicalInquiry.controller;


import com.lebang.medicalInquiry.constant.ResponseEnum;
import com.lebang.medicalInquiry.model.po.Physician;
import com.lebang.medicalInquiry.model.po.PhysicianCase;
import com.lebang.medicalInquiry.model.po.User;
import com.lebang.medicalInquiry.model.vo.PageVo;
import com.lebang.medicalInquiry.response.Callback;
import com.lebang.medicalInquiry.response.JsonData;
import com.lebang.medicalInquiry.service.PhysicianService;
import com.lebang.medicalInquiry.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.List;

@RequestMapping("/user")
@Api(tags = "用户相关")
@RestController
@Validated
public class UserController {


    @Autowired
    private UserService service;

    @GetMapping("/")
    @ApiOperation("用户列表")
    public JsonData<PageVo<List<User>>> listArticle(HttpServletRequest request, HttpServletResponse response,
                                                    @ApiParam(name = "keyWord", value = "标题关键词") @RequestParam(value = "keyWord", required = false) String keyWord,
                                                    @ApiParam(name = "state", value = "0 禁用 1 启用 -1 所有") @RequestParam(value = "state", required = false, defaultValue = "-1") Integer state,
                                                    @ApiParam(name = "sex", value = "boy girl") @RequestParam(value = "sex", required = false) String sex,
                                                    @ApiParam(name = "page", value = "页码") @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                    @ApiParam(name = "limit", value = "条数") @RequestParam(value = "limit", defaultValue = "10") Integer limit) {

        PageVo<List<User>> list = service.getList(keyWord, state, sex, page, limit);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), list);

    }

    @PostMapping("/")
    @ApiOperation("修改用户数据")
    public JsonData operator(HttpServletRequest request, HttpServletResponse response
            , @RequestBody User po

    ) {


        service.operator(po);

        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }
}